package com.hq.string;

import java.util.Arrays;

/**
 * @ClassName Demo
 * @Description TODO
 * @Author huangzl
 * @Date 2019/12/31 9:56
 * @Version 1.0
 **/
public class Demo {

    public static void main(String[] args) {
        String str = "how are you";
        StringBuilder stringBuilder = new StringBuilder(str);
        StringBuilder reverse = stringBuilder.reverse();
        char[] chars = reverse.toString().toCharArray();
        System.out.println(Arrays.toString(chars));

        //字符串排序
        String str2 = "qasfvd";
        char[] charArray = str2.toCharArray();
        Arrays.sort(charArray);
        System.out.println(charArray);

        //统计单词个数
        String str3 = "i am a good boy";
        String replace = str3.replace(" ", "");
        System.out.println(replace.length());

        System.out.println("单词反转----------------------->");
        //单词反转
        StringBuilder builder = new StringBuilder();
        String str4 = "the sky is blue";
        String[] split = str4.split("\\s+");
        for (String s : split) {
            if(!s.isEmpty()){
                builder.insert(0," ");
            }
            builder.insert(0,s);
        }
        System.out.println(builder);
    }

    /**
     * @param str1
     * @param str2
     * @return
     */
    private static Boolean sort(String str1, String str2) {
        char[] chars1 = str1.toCharArray();
        char[] chars2 = str2.toCharArray();
        Arrays.sort(chars1);
        Arrays.sort(chars2);

        str1 = chars1.toString();
        str2 = chars2.toString();
        if (str1.equals(str2)) {
            return true;
        }
        return false;
    }

}